package me.baicai.weixin.identity.repository;

import me.baicai.weixin.application.Result;
import me.baicai.weixin.entity.identity.Identity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * @description:
 * @author: [ 超级大白菜 ]
 * @date: 2019-11-09 16:47
 */
@Repository
public interface LoginRepository extends JpaRepository<Identity, Long>
{
    boolean existsByOpenid(String openId);

    Identity getById(Integer id);

    Identity getIdentityById(Integer id);

    Identity findByOpenid(String openid);

    Page<Identity> findAllById(Integer id, Pageable pageable);

    Page<Identity> findAllByOpenid(String openid, Pageable pageable);

    Page<Identity> findAllByNameLike(String name, Pageable pageable);

    Page<Identity> findAllByNickNameLike(String name, Pageable pageable);

    @Query(value = "select count(1) from identity t where TO_DAYS(t.created) = TO_DAYS(now())", nativeQuery = true)
    Integer getTodayCount();


    Page<Identity> findAllByIdAndType(Integer id, String type, Pageable pageable);

    Page<Identity> findAllByOpenidAndType(String openid, String type, Pageable pageable);

    Page<Identity> findAllByNameLikeAndType(String name, String type, Pageable pageable);

    Page<Identity> findAllByType(String shop, Pageable pageable);
}
